package com.itheimaoa.service.process.impl;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheimaoa.domain.process.Qualification;
import com.itheimaoa.service.base.impl.CommonServiceImpl;
import com.itheimaoa.service.process.IQualificationService;

@Service
@Transactional
public class QualificationServiceImpl extends CommonServiceImpl<Qualification> implements IQualificationService {
	@Override
	@Transactional(readOnly = true)
	public Qualification findApplyId(String applyId) {
		String jpql = " from Qualification o where o.apply.aid = ? order by o.uptime desc";
		List<Qualification> qualifications = this.hibernateTemplate.find(jpql, applyId);
		if (qualifications != null && qualifications.size() > 0) {
			qualifications.get(0);
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public Qualification findQualificationByApplyId(String applyId) {
		String jpql = " from Qualification o where o.apply.aid = ?";
		List<Qualification> qualifications = this.hibernateTemplate.find(jpql, applyId);
		if (qualifications != null && qualifications.size() > 0) {
			for (Qualification q : qualifications) {
				if (!q.getAgree()) {
					return q;
				}
			}
		}
		return null;
	}

	@Override
	@Transactional(readOnly = true)
	public List<Qualification> findQualificationsByApplyId(String applyId) {
		String jpql = " from Qualification o where o.apply.aid = ? order by o.uptime asc";
		List<Qualification> qualifications = this.hibernateTemplate.find(jpql, applyId);
		return qualifications;
	}

}
